$(function(){
	var aImg = $('.banner').find('img');
	var aBannerbtn = $('.banner').find('span');
	var prev = $('#prev');
	var next = $('#next');
	var Index=1;
	next.click(function(){
		Index++;
		if(Index<=3){
			aImg.fadeOut(0);
			aImg.eq(Index-1).fadeIn(500);
			aBannerbtn.attr('class','');
			aBannerbtn.eq(Index-1).attr('class','on');
		}
		else{
			Index=1;
			aImg.fadeOut(0);
			aImg.eq(Index-1).fadeIn(500);
			aBannerbtn.attr('class','');
			aBannerbtn.eq(Index-1).attr('class','on');
			return Index;
		}
	});
	prev.click(function(){
		Index--;
		if(Index<0){
			Index=3;
			aImg.fadeOut(0);
			aImg.eq(Index-1).fadeIn(500);
			aBannerbtn.attr('class','');
			aBannerbtn.eq(Index-1).attr('class','on');
			return Index;
		}
		else{
			aImg.fadeOut(0);
			aImg.eq(Index-1).fadeIn(500);
			aBannerbtn.attr('class','');
			aBannerbtn.eq(Index-1).attr('class','on');
		}
	});
	var timer = setInterval(function(){
		next.click();
	},3000);
	var banner = $('.banner');
	banner.mouseover(function(){
		clearTimeout(timer);
	});
	banner.mouseout(function(){
		timer = setInterval(function(){
			next.click();
		},3000);
	});
	var boxprev = $('.box-prev');
	var boxnext = $('.box-next');
	var boxdp = $('.box-dp');
	boxprev.click(function(){
		boxdp.animate({left:'0'});
		boxnext.css('color','#999');
		$(this).css('color','#ccc');
	});
	boxnext.click(function(){
		boxdp.animate({left:'-1275px'});
		boxprev.css('color','#999');
		$(this).css('color','#ccc');
	});
	/*single*/
	$(window).on('scroll',function(){
		if($(window).scrollTop() < 150){
			$(".single-header").css('position','relative');
			$(".single-header").css('top','150px');
		}
		else if($(window).scrollTop()>150){
			$(".single-header").css('position','fixed');
			$(".single-header").css('top','0px');
		}
	});
	var btn_tags = $('.btn-tags');
    var btn_tags2 = $('.btn-tags2');
	var btn_color = $('.btn-color');
	var single_tit_p = $('.single-title').find('p');
	btn_tags.click(function(){
		btn_tags.removeClass('active');
		$(this).addClass('active');
		var txt1 = $('.active').find('.name').text();
		var txt2 = $('.active-color').find('span').text();
		single_tit_p.html(txt1+' '+txt2);
		$('.single-title').find('span').html('总计：'+$('.active').find('.price').text());
		$('.pro-info').find('span').eq(0).html($('.active').find('.price').text());
		$('#price').val($('.active').find('.price').text().slice(0,-1));
	});
    btn_tags2.click(function(){
        btn_tags2.removeClass('active');
        $(this).addClass('active');
        var txt1 = $('.active').find('.name').text();
        var txt2 = $('.active-color').find('span').text();
        single_tit_p.html(txt1+' '+txt2);
    });
	btn_color.click(function(){
		btn_color.removeClass('active-color');
		$(this).addClass('active-color');
		var txt1 = $('.active').find('.name').text();
		var txt2 = $('.active-color').find('span').text();
		single_tit_p.html(txt1+' '+txt2);
	});

	/*settlement*/
	var mask = $('.mask');
	var add_cart = $('.add-cart');
	var address_add = $('.address-add');
	var address_btn = $('.add-cart').find('input:submit');
	var address_cart = $('.address-cart');
	address_cart.click(function(){
		address_cart.removeClass('address_cart');
		$(this).addClass('address-active');
	});
	address_add.click(function(){
		mask.css('display','block');
		add_cart.fadeIn();
	});
	address_btn.click(function(){
		mask.css('display','none');
		add_cart.fadeOut();
	});
});